<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.6"/>
<title>easykf-2.04: example-001.cc</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">easykf-2.04
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.6 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">example-001.cc</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><span class="comment">/* example-001.cc</span></div>
<div class="line"><span class="comment"> * </span></div>
<div class="line"><span class="comment"> * Copyright (C) 2011-2014 Jeremy Fix</span></div>
<div class="line"><span class="comment"> * </span></div>
<div class="line"><span class="comment"> * This program is free software; you can redistribute it and/or modify</span></div>
<div class="line"><span class="comment"> * it under the terms of the GNU General Public License as published by</span></div>
<div class="line"><span class="comment"> * the Free Software Foundation; either version 3 of the License, or (at</span></div>
<div class="line"><span class="comment"> * your option) any later version.</span></div>
<div class="line"><span class="comment"> * </span></div>
<div class="line"><span class="comment"> * This program is distributed in the hope that it will be useful, but</span></div>
<div class="line"><span class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</span></div>
<div class="line"><span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span></div>
<div class="line"><span class="comment"> * General Public License for more details.</span></div>
<div class="line"><span class="comment"> * </span></div>
<div class="line"><span class="comment"> * You should have received a copy of the GNU General Public License</span></div>
<div class="line"><span class="comment"> * along with this program; if not, write to the Free Software</span></div>
<div class="line"><span class="comment"> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"></div>
<div class="line"><span class="comment">/* In this example, we learn the XOR with a 2-2-1 MLP */</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &lt;cstdlib&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;cmath&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;fstream&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="ukf_8h.html">ukf.h</a>&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#define VERBOSE true</span></div>
<div class="line"><span class="preprocessor"></span></div>
<div class="line"><span class="keyword">using namespace </span>ukf::parameter;</div>
<div class="line"></div>
<div class="line"><span class="comment">/*****************************************************/</span></div>
<div class="line"><span class="comment">/*            Definition of the MLP                  */</span></div>
<div class="line"><span class="comment">/*****************************************************/</span></div>
<div class="line"></div>
<div class="line"><span class="keywordtype">double</span> transfer(<span class="keywordtype">double</span> x)</div>
<div class="line">{</div>
<div class="line">    <span class="comment">//return 2.0 / (1.0 + exp(-x))-1.0;</span></div>
<div class="line">    <span class="comment">//return tanh(x);</span></div>
<div class="line">  <span class="keywordflow">return</span> 1.0 / (1.0 + exp(-x));</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">double</span> my_func(gsl_vector * param, gsl_vector * input)</div>
<div class="line">{</div>
<div class="line">    <span class="keywordtype">double</span> y0,y1,z;</div>
<div class="line">    y0 = 0.0;</div>
<div class="line">    y1 = 0.0;</div>
<div class="line">    <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0 ; i &lt; 2 ; i++)</div>
<div class="line">    {</div>
<div class="line">        y0 += gsl_vector_get(param,i) * gsl_vector_get(input, i);</div>
<div class="line">    }</div>
<div class="line">    y0 = y0 + gsl_vector_get(param,2);</div>
<div class="line">    y0 = transfer(y0);</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0 ; i &lt; 2 ; i++)</div>
<div class="line">    {</div>
<div class="line">        y1 += gsl_vector_get(param,3+i) * gsl_vector_get(input, i);</div>
<div class="line">    }</div>
<div class="line">    y1 = y1 + gsl_vector_get(param,5);</div>
<div class="line">    y1 = transfer(y1);</div>
<div class="line"></div>
<div class="line">    z = gsl_vector_get(param,6) * y0 + gsl_vector_get(param,7)*y1 + gsl_vector_get(param,8);</div>
<div class="line">    z = transfer(z);</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">return</span> z;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="comment">/*****************************************************/</span></div>
<div class="line"><span class="comment">/*                    main                           */</span></div>
<div class="line"><span class="comment">/*****************************************************/</span></div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* argv[]) {</div>
<div class="line"></div>
<div class="line">   srand(time(NULL));</div>
<div class="line"></div>
<div class="line">   <span class="comment">// Definition of the parameters and state variables</span></div>
<div class="line">   <a name="_a0"></a><a class="code" href="structukf_1_1parameter_1_1ukf__param.html">ukf_param</a> p;</div>
<div class="line">   <a name="_a1"></a><a class="code" href="structukf_1_1parameter_1_1ukf__scalar__state.html">ukf_scalar_state</a> s;</div>
<div class="line"></div>
<div class="line">   <span class="comment">// Initialization of the parameters</span></div>
<div class="line">   p.<a name="a2"></a><a class="code" href="structukf_1_1parameter_1_1ukf__param.html#afdb1ce39c4a72e31df41314e2e4c4090">n</a> = 9;</div>
<div class="line">   p.<a name="a3"></a><a class="code" href="structukf_1_1parameter_1_1ukf__param.html#a6226f46479a98fdeb1321d49680e76ed">kpa</a> = 3.0 - p.<a class="code" href="structukf_1_1parameter_1_1ukf__param.html#afdb1ce39c4a72e31df41314e2e4c4090">n</a>;</div>
<div class="line">   p.<a name="a4"></a><a class="code" href="structukf_1_1parameter_1_1ukf__param.html#a41e15863dacadc709c856810fec793da">alpha</a> = 1e-1;</div>
<div class="line">   p.<a name="a5"></a><a class="code" href="structukf_1_1parameter_1_1ukf__param.html#a3afc7edee6fb3dd28849f2219c079b30">beta</a> = 2.0;</div>
<div class="line"></div>
<div class="line">   <span class="comment">//EvolutionNoise * evolution_noise = new EvolutionRLS(1e-4, 0.9995);</span></div>
<div class="line">   <a name="_a6"></a><a class="code" href="classukf_1_1parameter_1_1EvolutionNoise.html">EvolutionNoise</a> * evolution_noise = <span class="keyword">new</span> <a name="_a7"></a><a class="code" href="classukf_1_1parameter_1_1EvolutionRobbinsMonro.html">EvolutionRobbinsMonro</a>(1e-2, 1e-5);</div>
<div class="line">   p.<a name="a8"></a><a class="code" href="structukf_1_1parameter_1_1ukf__param.html#a84f1c71ab2cd9fc6063790e9942637bd">evolution_noise</a> = evolution_noise;</div>
<div class="line"></div>
<div class="line">   p.<a name="a9"></a><a class="code" href="structukf_1_1parameter_1_1ukf__param.html#ade187fc4a6cf6c6e9a1fcb5cf8898985">observation_noise</a> = 1e-1;</div>
<div class="line">   p.<a name="a10"></a><a class="code" href="structukf_1_1parameter_1_1ukf__param.html#a898c9583fba45551ae39213dd2b212ba">prior_pi</a> = 1e-1;</div>
<div class="line"></div>
<div class="line">   <span class="comment">// Initialization of the state and parameters</span></div>
<div class="line">   <a name="a11"></a><a class="code" href="namespaceukf_1_1parameter.html#a4f5d4fb6f2a2be962a1528a40f8c9562">ukf_scalar_init</a>(p,s);</div>
<div class="line"></div>
<div class="line">   <span class="comment">// Initialize the parameter vector to some random values</span></div>
<div class="line">   <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0 ; i &lt; p.<a class="code" href="structukf_1_1parameter_1_1ukf__param.html#afdb1ce39c4a72e31df41314e2e4c4090">n</a> ; i++)</div>
<div class="line">      gsl_vector_set(s.<a name="a12"></a><a class="code" href="structukf_1_1parameter_1_1ukf__scalar__state.html#a8c307cba37cbabda94b66ab911e14122">w</a>,i,0.01*(2.0*rand()/<span class="keywordtype">double</span>(RAND_MAX-1)-1.0));</div>
<div class="line"></div>
<div class="line"></div>
<div class="line">   <span class="comment">// Allocate the input/output vectors</span></div>
<div class="line">   gsl_vector * xi = gsl_vector_alloc(2);</div>
<div class="line">   <span class="keywordtype">double</span> yi=0.0;</div>
<div class="line"></div>
<div class="line">   <span class="comment">// Define the training dataset</span></div>
<div class="line">   <span class="comment">/*double x[4] = {-1.0,1.0,-1.0,1.0};</span></div>
<div class="line"><span class="comment">   double y[4] = {-1.0,-1.0,1.0,1.0};</span></div>
<div class="line"><span class="comment">   double z[4] = {-1.0,1.0,1.0,-1.0};*/</span></div>
<div class="line">   <span class="keywordtype">double</span> x[4] = {0.0,1.0,0.0,1.0};</div>
<div class="line">   <span class="keywordtype">double</span> y[4] = {0.0,0.0,1.0,1.0};</div>
<div class="line">   <span class="keywordtype">double</span> z[4] = {0.0,1.0,1.0,0.0};</div>
<div class="line"></div>
<div class="line">   <span class="comment">// Define some limit conditions for the learning</span></div>
<div class="line">   <span class="keywordtype">double</span> errorBound = 1e-4;</div>
<div class="line">   <span class="keywordtype">int</span> nbStepsLimit = 10000;</div>
<div class="line">   <span class="keywordtype">double</span> error = 2*errorBound;;</div>
<div class="line"></div>
<div class="line">   <span class="comment">/***********************************************/</span></div>
<div class="line">   <span class="comment">/***** Computing the error before learning *****/</span></div>
<div class="line">   <span class="comment">/***********************************************/</span></div>
<div class="line"></div>
<div class="line">   error = 0.0;</div>
<div class="line">   std::cout &lt;&lt; <span class="stringliteral">&quot;###########\n Before learning : &quot;</span> &lt;&lt; std::endl;</div>
<div class="line">   <span class="keywordflow">for</span>(<span class="keywordtype">int</span> j = 0 ; j &lt; 4 ; j++)</div>
<div class="line">   {</div>
<div class="line">       gsl_vector_set(xi,0,x[j]);</div>
<div class="line">       gsl_vector_set(xi,1,y[j]);</div>
<div class="line">       <a name="a13"></a><a class="code" href="namespaceukf_1_1parameter.html#a9b3034fa2b941068c2fc0fea41cbd5fb">ukf_scalar_evaluate</a>(p, s, my_func,xi,yi);</div>
<div class="line">       std::cout &lt;&lt; x[j] &lt;&lt; <span class="stringliteral">&quot; ; &quot;</span> &lt;&lt; y[j] &lt;&lt; <span class="stringliteral">&quot; -&gt; &quot;</span> &lt;&lt; yi &lt;&lt; <span class="stringliteral">&quot; mean = &quot;</span> &lt;&lt; yi &lt;&lt;  <span class="stringliteral">&quot; desired : &quot;</span> &lt;&lt; z[j] &lt;&lt; std::endl;</div>
<div class="line"></div>
<div class="line">       error += pow(yi - z[j],2.0);</div>
<div class="line">   }</div>
<div class="line">   error = sqrt(error / 4.0);</div>
<div class="line">   std::cout &lt;&lt; <span class="stringliteral">&quot;RMS : &quot;</span> &lt;&lt; error &lt;&lt; std::endl;</div>
<div class="line">   std::cout &lt;&lt; <span class="stringliteral">&quot;###########\n &quot;</span> &lt;&lt; std::endl;</div>
<div class="line"></div>
<div class="line">   <span class="comment">/***********************************************/</span></div>
<div class="line">   <span class="comment">/***** Iterate the learning on the samples *****/</span></div>
<div class="line">   <span class="comment">/***********************************************/</span></div>
<div class="line"></div>
<div class="line">   <span class="keywordtype">int</span> epoch = 0;</div>
<div class="line">   error = 2 * errorBound;</div>
<div class="line">   <span class="keywordflow">while</span>( epoch &lt;= nbStepsLimit &amp;&amp; error &gt; errorBound)</div>
<div class="line">   {</div>
<div class="line">       <span class="comment">// Iterate on the samples</span></div>
<div class="line">       <span class="keywordflow">for</span>(<span class="keywordtype">int</span> j = 0 ; j &lt; 4 ; j++)</div>
<div class="line">       {</div>
<div class="line">           gsl_vector_set(xi,0,x[j]);</div>
<div class="line">           gsl_vector_set(xi,1,y[j]);</div>
<div class="line">           <a name="a14"></a><a class="code" href="namespaceukf_1_1parameter.html#ae4830e1c0b576662494d63623dcf59dc">ukf_scalar_iterate</a>(p, s, my_func,xi,z[j]);</div>
<div class="line">       }</div>
<div class="line"></div>
<div class="line">       <span class="comment">// Evaluate the error on the data set</span></div>
<div class="line">       error = 0.0;</div>
<div class="line">       <span class="keywordflow">for</span>(<span class="keywordtype">int</span> j = 0 ; j &lt; 4 ; j++)</div>
<div class="line">       {</div>
<div class="line">           gsl_vector_set(xi,0,x[j]);</div>
<div class="line">           gsl_vector_set(xi,1,y[j]);</div>
<div class="line"></div>
<div class="line">           <span class="comment">// Evaluate the function using the sigma points</span></div>
<div class="line">           <span class="comment">//ukf_scalar_evaluate(p, s, my_func,xi,yi);</span></div>
<div class="line"></div>
<div class="line">           <span class="comment">// Or the function itself, which is less expensive</span></div>
<div class="line">           yi = my_func(s.<a class="code" href="structukf_1_1parameter_1_1ukf__scalar__state.html#a8c307cba37cbabda94b66ab911e14122">w</a>,xi);</div>
<div class="line"></div>
<div class="line">           error += pow(yi - z[j],2.0);</div>
<div class="line">       }</div>
<div class="line">       error = sqrt(error / 4.0);</div>
<div class="line">       <span class="keywordflow">if</span>(VERBOSE)</div>
<div class="line">           std::cout &lt;&lt; <span class="stringliteral">&quot;Epoch &quot;</span> &lt;&lt; epoch &lt;&lt; <span class="stringliteral">&quot; error = &quot;</span> &lt;&lt; error &lt;&lt; std::endl;</div>
<div class="line">       epoch++;</div>
<div class="line">   }</div>
<div class="line">   std::cout &lt;&lt; <span class="stringliteral">&quot; Run on &quot;</span> &lt;&lt; epoch &lt;&lt; <span class="stringliteral">&quot; epochs ; RMS = &quot;</span> &lt;&lt; error &lt;&lt; <span class="stringliteral">&quot;\n&quot;</span> &lt;&lt; std::endl ;</div>
<div class="line"></div>
<div class="line">   <span class="comment">/***********************************************/</span></div>
<div class="line">   <span class="comment">/**** Test the function on the training set ****/</span></div>
<div class="line">   <span class="comment">/***********************************************/</span></div>
<div class="line"></div>
<div class="line">   std::cout &lt;&lt; <span class="stringliteral">&quot;###########\n After learning : &quot;</span> &lt;&lt; std::endl;</div>
<div class="line">   <span class="keywordflow">for</span>(<span class="keywordtype">int</span> j = 0 ; j &lt; 4 ; j++)</div>
<div class="line">   {</div>
<div class="line">       gsl_vector_set(xi,0,x[j]);</div>
<div class="line">       gsl_vector_set(xi,1,y[j]);</div>
<div class="line">       <a class="code" href="namespaceukf_1_1parameter.html#a9b3034fa2b941068c2fc0fea41cbd5fb">ukf_scalar_evaluate</a>(p, s, my_func,xi,yi);</div>
<div class="line">       <span class="comment">//yi = my_func(s.w,xi);</span></div>
<div class="line">       std::cout &lt;&lt; x[j] &lt;&lt; <span class="stringliteral">&quot; ; &quot;</span> &lt;&lt; y[j] &lt;&lt; <span class="stringliteral">&quot; -&gt; &quot;</span> &lt;&lt; yi &lt;&lt; <span class="stringliteral">&quot; desired : &quot;</span> &lt;&lt; z[j] &lt;&lt; std::endl;</div>
<div class="line">   }</div>
<div class="line"></div>
<div class="line">   <span class="comment">/***********************************************/</span></div>
<div class="line">   <span class="comment">/****     Display the learned parameters    ****/</span></div>
<div class="line">   <span class="comment">/***********************************************/</span></div>
<div class="line"></div>
<div class="line">   std::cout &lt;&lt; std::endl;</div>
<div class="line">   std::cout &lt;&lt; <span class="stringliteral">&quot;Parameters : &quot;</span> &lt;&lt; std::endl;</div>
<div class="line">   <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0 ; i &lt; 2 ; i++)</div>
<div class="line">   {</div>
<div class="line">       std::cout &lt;&lt; <span class="stringliteral">&quot;x[&quot;</span> &lt;&lt; i &lt;&lt; <span class="stringliteral">&quot;] -- (&quot;</span> &lt;&lt; gsl_vector_get(s.<a class="code" href="structukf_1_1parameter_1_1ukf__scalar__state.html#a8c307cba37cbabda94b66ab911e14122">w</a>,i) &lt;&lt; <span class="stringliteral">&quot;) --&gt; y[0] &quot;</span> &lt;&lt; std::endl;</div>
<div class="line">   }</div>
<div class="line">   std::cout &lt;&lt; <span class="stringliteral">&quot;Bias y[0] : &quot;</span> &lt;&lt; gsl_vector_get(s.<a class="code" href="structukf_1_1parameter_1_1ukf__scalar__state.html#a8c307cba37cbabda94b66ab911e14122">w</a>,2) &lt;&lt; std::endl;</div>
<div class="line"></div>
<div class="line">   std::cout &lt;&lt; std::endl;</div>
<div class="line">   <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0 ; i &lt; 2 ; i++)</div>
<div class="line">   {</div>
<div class="line">       std::cout &lt;&lt; <span class="stringliteral">&quot;x[&quot;</span> &lt;&lt; i &lt;&lt; <span class="stringliteral">&quot;] -- (&quot;</span> &lt;&lt; gsl_vector_get(s.<a class="code" href="structukf_1_1parameter_1_1ukf__scalar__state.html#a8c307cba37cbabda94b66ab911e14122">w</a>,3+i) &lt;&lt; <span class="stringliteral">&quot;) --&gt; y[1] &quot;</span> &lt;&lt; std::endl;</div>
<div class="line">   }</div>
<div class="line">   std::cout &lt;&lt; <span class="stringliteral">&quot;Bias y[1] : &quot;</span> &lt;&lt; gsl_vector_get(s.<a class="code" href="structukf_1_1parameter_1_1ukf__scalar__state.html#a8c307cba37cbabda94b66ab911e14122">w</a>,5) &lt;&lt; std::endl;</div>
<div class="line"></div>
<div class="line">   std::cout &lt;&lt; std::endl;</div>
<div class="line">   std::cout &lt;&lt; <span class="stringliteral">&quot;y[0] -- (&quot;</span> &lt;&lt; gsl_vector_get(s.<a class="code" href="structukf_1_1parameter_1_1ukf__scalar__state.html#a8c307cba37cbabda94b66ab911e14122">w</a>,6) &lt;&lt; <span class="stringliteral">&quot;) --&gt; z &quot;</span> &lt;&lt; std::endl;</div>
<div class="line">   std::cout &lt;&lt; <span class="stringliteral">&quot;y[1] -- (&quot;</span> &lt;&lt; gsl_vector_get(s.<a class="code" href="structukf_1_1parameter_1_1ukf__scalar__state.html#a8c307cba37cbabda94b66ab911e14122">w</a>,7) &lt;&lt; <span class="stringliteral">&quot;) --&gt; z &quot;</span> &lt;&lt; std::endl;</div>
<div class="line">   std::cout &lt;&lt; <span class="stringliteral">&quot;Bias z : &quot;</span> &lt;&lt; gsl_vector_get(s.<a class="code" href="structukf_1_1parameter_1_1ukf__scalar__state.html#a8c307cba37cbabda94b66ab911e14122">w</a>,8) &lt;&lt; std::endl;</div>
<div class="line"></div>
<div class="line">   std::cout &lt;&lt; <span class="stringliteral">&quot;########### &quot;</span> &lt;&lt; std::endl;</div>
<div class="line"></div>
<div class="line">   <span class="comment">/***********************************************/</span></div>
<div class="line">   <span class="comment">/**** Generate a PPM of the classification  ****/</span></div>
<div class="line">   <span class="comment">/***********************************************/</span></div>
<div class="line"></div>
<div class="line">   std::cout &lt;&lt; <span class="stringliteral">&quot;Generating output image in example-001.ppm&quot;</span> &lt;&lt; std::endl;</div>
<div class="line">   <span class="keywordtype">double</span> x_min, x_max, y_min, y_max;</div>
<div class="line">   x_min = -1.0;</div>
<div class="line">   x_max = 1.0;</div>
<div class="line">   y_min = -1.0;</div>
<div class="line">   y_max = 1.0;</div>
<div class="line">   <span class="keywordtype">int</span> N = 100;</div>
<div class="line">   <span class="keywordtype">int</span> color;</div>
<div class="line">   std::ofstream image(<span class="stringliteral">&quot;example-001.ppm&quot;</span>);</div>
<div class="line">   image &lt;&lt; <span class="stringliteral">&quot;P3&quot;</span> &lt;&lt; std::endl &lt;&lt; <span class="stringliteral">&quot;# example-001.ppm&quot;</span> &lt;&lt; std::endl;</div>
<div class="line">   image &lt;&lt; N &lt;&lt; <span class="stringliteral">&quot; &quot;</span> &lt;&lt; N &lt;&lt; std::endl;</div>
<div class="line">   image &lt;&lt; <span class="stringliteral">&quot;255&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"></div>
<div class="line">   <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0 ; i &lt; N ; i++)</div>
<div class="line">     {</div>
<div class="line">       <span class="keywordflow">for</span>(<span class="keywordtype">int</span> j = 0 ; j &lt; N ; j++)</div>
<div class="line">         {</div>
<div class="line">           gsl_vector_set(xi, 0, x_min + j*(x_max - x_min)/<span class="keywordtype">double</span>(N-1));</div>
<div class="line">           gsl_vector_set(xi, 1, y_min + (N-1-i)*(y_max - y_min)/<span class="keywordtype">double</span>(N-1));</div>
<div class="line"></div>
<div class="line">           <span class="comment">// Evaluate the output as the mean of the images of the sigma points</span></div>
<div class="line">           <span class="comment">//ukf_scalar_evaluate(p, s, my_func,xi,yi);</span></div>
<div class="line">           yi = my_func(s.<a class="code" href="structukf_1_1parameter_1_1ukf__scalar__state.html#a8c307cba37cbabda94b66ab911e14122">w</a>, xi);</div>
<div class="line">           color = int(255.0*(1.0 + yi)/2.0);</div>
<div class="line">           image &lt;&lt; color &lt;&lt; <span class="stringliteral">&quot; &quot;</span> &lt;&lt; color &lt;&lt; <span class="stringliteral">&quot; &quot;</span> &lt;&lt; color &lt;&lt; <span class="stringliteral">&quot; &quot;</span> ;</div>
<div class="line">         }</div>
<div class="line">       image &lt;&lt; std::endl;</div>
<div class="line">     }</div>
<div class="line">   image.close();</div>
<div class="line"></div>
<div class="line">   <span class="comment">/***********************************************/</span></div>
<div class="line">   <span class="comment">/****            Free the memory            ****/</span></div>
<div class="line">   <span class="comment">/***********************************************/</span></div>
<div class="line">   <a name="a15"></a><a class="code" href="namespaceukf_1_1parameter.html#a18d91f67e6de67928a223b50950ffdae">ukf_scalar_free</a>(p,s);</div>
<div class="line">}</div>
</div><!-- fragment --> </div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.6
</small></address>
</body>
</html>
